﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace CS
{
    public partial class Form1 : Form
    {
        void ok()
        {
            MessageBox.Show("第" + Convert.ToString(hq) + "步\n" + "黑棋胜利\n游戏结束", "黑棋胜利", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
        void no()
        {
            MessageBox.Show("第" + Convert.ToString(bq) + "步\n" + "AI胜利\n游戏结束", "AI胜利", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
        void bb(int q)
        {
            button[q].BackgroundImage = Image.FromFile("imgdata\\白棋.jpg");
            a[q] = 1;
            w[q] = 2;
        }
        public Form1()
        {
            InitializeComponent();
            Width = 840;
            Height = 800;
        }
        private Button[] button = new Button[361];
        private Label[] label = new Label[3];
        //  public int intHour, intMouit, intSecon;
        int m = 0;
        int yg = 0, bq = 0, hq = 0;
        int index, t, zd;
        int[] a = new int[361];
        int[] w = new int[361];
        int[] aiiq = new int[361];
        int aisys = 0;
        int x = 0, y = 0, z = 0;
        int oooo = 0, ls = 0;
        int bj = 1;
        int ls1;
        private void Form1_Load(object sender, EventArgs e)
        {
            int h = 0, l = 0;
            label6.Text = Convert.ToString(yg);
            label5.Text = Convert.ToString(bq);
            label4.Text = Convert.ToString(hq);
            for (int i = 0; i < 3; i++)
            {
                label[i] = new Label();
                if (i == 0)
                {
                    label[i].Location = new Point(872, 238);
                    label[i].Text = "黑";
                    label[i].BackColor = Color.Black;
                }
                if (i == 1)
                {
                    label[i].Text = "白";
                }
                if (i == 2)
                {
                    label[i].Text = "一共";
                }
            }
            for (int i = 0; i < 361; i++)
            {
                button[i] = new Button();
                button[i].Width = 40;
                button[i].Height = 40;
                //button[i].Text = "按钮" + (i + 1).ToString();
                button[i].BackColor = Color.Violet;
                button1.BackgroundImage = Image.FromFile(@"imgdata\黑棋.jpg");
                if (i >= 2 && i <= 16)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\上边棋盘.jpg");
                }
                else if (i >= 344 && i != 359 && i != 343 && i != 360)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\下边棋盘.jpg");
                }
                else if ((i - 1) % 19 == 0 && i != 1 && i != 343)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\左边棋盘.jpg");
                }
                else if ((i + 2) % 19 == 0 && i != 17 && i != 359)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\右边棋盘.jpg");
                }
                else if (i == 1)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\左上角棋盘.jpg");
                }
                else if (i == 17)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\右上角棋盘.jpg");
                }
                else if (i == 343)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\左下角棋盘.jpg");
                }
                else if (i == 359)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\右下角棋盘.jpg");
                }
                else if (i == 60 || i == 66 || i == 72 || i == 174 || i == 180 || i == 186 || i == 288 || i == 294 || i == 300)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\黑点棋盘.jpg");
                }
                else if (i % 19 == 0 || (i + 1) % 19 == 0 || i == 360)
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\1.jpg");
                }
                else
                {
                    button[i].BackgroundImage = Image.FromFile(@"imgdata\普通棋盘.jpg");
                }
                button[i].TabIndex = i;//把i赋值给TabIndex用于之后定位
                //Black 黑
                //White 白
                button[i].Left = l;
                button[i].FlatStyle = FlatStyle.Flat;
                button[i].FlatAppearance.BorderSize = 0;
                l = l + 40;
                button[i].Top = h;
                button[i].Click += new System.EventHandler(this.button1_Click);
                this.Controls.Add(button[i]);
                if (l >= 760)
                {
                    l = 0;
                    h = h + 40;
                }
                for (x = 0; x <= 360; x++)
                {
                    if (x % 19 == 0 || (x + 1) % 19 == 0)
                    {
                        w[x] = 3;
                        a[x] = 1;
                    }
                }
            }
        }
        void ai(int yy)
        {
            
            bq += 1; yg += 1;
            label6.Text = Convert.ToString(yg);
            label5.Text = Convert.ToString(bq);
            label4.Text = Convert.ToString(hq);
            aisys = 0;
            ///判断自己00.00可能胜利*****************************************************************************************


            for (x = 0; x < 360; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x + y * 19 <= 360)
                    {
                        if (w[x] != 1)
                        {
                            if (w[x + y * 19] == 0)
                            {
                                oooo = x + y * 19;
                            }
                            if (w[x + y * 19] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;



                for (y = 0; y < 5; y++)
                {
                    if (x + x * 1 <= 360)
                    {
                        if (w[x] != 1)
                        {
                            if ((x + y * 1) % 19 == 0)
                            {
                                break;
                            }
                            if (w[x + y * 1] == 0)
                            {
                                oooo = x + y * 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;


                for (y = 0; y < 5; y++)
                {
                    if (w[x] != 1)
                    {
                        if (x + (y * 19 + y * 1) <= 360)
                        {
                            if ((x + y * 19 + y * 1) % 19 == 0)
                            {
                                break;
                            }
                            if (w[x + y * 19 + y * 1] == 0)
                            {
                                oooo = x + y * 19 + y * 1;
                            }
                            if (w[x + y * 19 + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;



                for (y = 0; y < 5; y++)
                {
                    if (w[x] != 1)
                    {
                        if (x + (y * 19 - y * 1) <= 360)
                        {
                            if ((x + y * 19 - y * 1) + 1 % 19 == 0)
                            {
                                break;
                            }
                            if (w[x + y * 19 - y * 1] == 0)
                            {
                                oooo = x + y * 19 - y * 1;
                            }
                            if (w[x + y * 19 - y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;

            }
            /*
            //判断玩家有没有0.00**************************************************************************************

            for (x = 0; x < 360; x++)
            {
                for (y = 0; y < 4; y++)
                {
                    if (x + y * 19 <= 360)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 19] == 1)
                            {
                                z += 1;
                            }
                            if (w[x + y * 19] == 0)
                            {
                                oooo = x + y * 19;
                            }
                        }
                    }
                    if (z == 3)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;

                for (y = 0; y < 4; y++)
                {
                    if (x + y * 1 <= 360)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 1] == 1)
                            {
                                z += 1;
                            }
                            if (w[x + y * 1] == 0)
                            {
                                oooo = x + y * 1;
                            }
                        }
                    }
                    if (z == 3)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;

                for (y = 0; y < 4; y++)
                {
                    if (x + y * 19 + y * 1 <= 360)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 19 + y * 1] == 1)
                            {
                                z += 1;
                            }
                            if (w[x + y * 19 + y * 1] == 0)
                            {
                                oooo = x + y * 19 + y * 1;
                            }
                        }
                    }
                    if (z == 3)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;

                for (y = 0; y < 4; y++)
                {
                    if (x + y * 19 - y * 1 <= 360)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 19 - y * 1] == 1)
                            {
                                z += 1;
                            }
                            if (w[x + y * 19 - y * 1] == 0)
                            {
                                oooo = x + y * 19 - y * 1;
                            }
                        }
                    }
                    if (z == 3)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;

            }


            */



            ///判断玩家有没有000.0形式或者4连子*****************************************************************************************


            for (x = 0; x < 360; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x + (y * 19) <= 360)
                    {
                        if (w[x + y * 19] == 0)
                        {
                            oooo = x + y * 19;
                        }
                        if (w[x + y * 19] == 1)
                        {
                            z += 1;
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;

                for (y = 0; y < 5; y++)
                {
                    if (x + (y * 1) <= 360)
                    {

                        if (w[x + y * 1] == 0)
                        {
                            oooo = x + y * 1;
                        }

                        if (w[x + y * 1] == 1)
                        {
                            z += 1;
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {

                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }

                        }
                    }
                }
                z = 0;
                oooo = 0;



                for (y = 0; y < 5; y++)
                {
                    if (x + y * 19 + y * 1 <= 360)
                    {
                        if (w[x + y * 19 + y * 1] == 0)
                        {
                            oooo = x + y * 19 + y * 1;
                        }
                        if (w[x + y * 19 + y * 1] == 1)
                        {
                            z += 1;
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }

                        }
                    }
                }
                z = 0;
                oooo = 0;


                for (y = 0; y < 5; y++)
                {
                    if (x + y * 19 - y * 1 <= 360)
                    {
                        if (w[x + y * 19 - y * 1] == 0)
                        {
                            oooo = x + y * 19 - y * 1;
                        }
                        if (w[x + y * 19 - y * 1] == 1)
                        {
                            z += 1;
                        }
                    }
                    if (z == 4)
                    {
                        if (oooo != 0)
                        {
                            if (a[oooo] == 0)
                            {
                                bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;
                            }

                        }
                    }
                }
                z = 0;
                oooo = 0;


            }




            //判断玩家有没有00.0形式=======================================************************************
            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    for (y = 0; y < 4; y++)
                    {
                        if (x + x + 3 * 19 <= 360)
                        {
                            if (w[x] == 1 && w[x + 3 * 19] == 1)
                            {
                                if (w[x + y * 19] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19] == 0)
                                {
                                    oooo = x + y * 19;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 19] == 1)
                                {
                                    if (x + 3 * 19 <= 360)
                                    {
                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 4; y++)
                    {
                        if (x + 3 * 1 <= 360)
                        {
                            if (w[x] == 1 && w[x + 3 * 1] == 1)
                            {
                                if (w[x + y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 1] == 0)
                                {
                                    oooo = x + y * 1;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 1] == 1)
                                {
                                    if (x + y * 1 <= 360)
                                    {
                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 4; y++)
                    {
                        if (x + 3 * 19 + 3 * 1 <= 360)
                        {
                            if (w[x] == 1 && w[x + 3 * 19 + 3 * 1] == 1)
                            {
                                if (w[x + y * 19 + y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 + y * 1] == 0)
                                {
                                    oooo = x + y * 19 + y * 1;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 19 + 3 * 1] == 1)
                                {
                                    if (x + y * 19 + y * 1 <= 360)
                                    {
                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 4; y++)
                    {
                        if (x + 3 * 19 - 3 * 1 <= 360)
                        {
                            if (w[x] == 1 && w[x + 3 * 19 - 3 * 1] == 1)
                            {
                                if (w[x + y * 19 - y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 - y * 1] == 0)
                                {
                                    oooo = x + y * 19 - y * 1;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 19 - 3 * 1] == 1)
                                {
                                    if (x + y * 19 - y * 1 <= 360)
                                    {

                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;

                }
            }


            //判断AI有没有00.0形式=======================================************************************
            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 <= 360)
                        {
                            if (w[x] != 1)
                            {
                                if (w[x + y * 19] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19] == 0)
                                {
                                    oooo = x + y * 19;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 1 <= 360)
                        {
                            if (w[x] != 1)
                            {
                                if (w[x + y * 1] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 1] == 0)
                                {
                                    oooo = x + y * 1;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 + y * 1 <= 360)
                        {
                            if (w[x] != 1)
                            {
                                if (w[x + y * 19 + y * 1] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 + y * 1] == 0)
                                {
                                    oooo = x + y * 19 + y * 1;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 - y * 1 <= 360)
                        {
                            if (w[x] != 1)
                            {
                                if (w[x + y * 19 - y * 1] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 - y * 1] == 0)
                                {
                                    oooo = x + y * 19 - y * 1;
                                }
                            }
                        }

                        if (z == 3)
                        {
                            if (oooo != 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;

                }
            }






            ///判断AI有没有还差一颗四连（在上半部分落子）*****************************************************************************************

            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 19] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19] != 2)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 19 >= 0 && x + 3 * 19 <= 359)
                            {
                                if (w[x - 19] == 0 && w[x + 3 * 19] == 0 )
                                {
                                    if (a[x - 19] == 0)
                                    {
                                        bb(x - 19);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 1 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 1] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 1] != 2)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 1 >= 0 && x + 3 * 1 <= 359)
                            {
                                if (w[x - 1] == 0 && w[x + 3 * 1] == 0 )
                                {
                                    if (a[x - 1] == 0)
                                    {
                                        bb(x - 1);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 + y * 1 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 19 + y * 1] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 + y * 1] != 2)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 20 >= 0 && x + 3 * 19 + 3 <= 359)
                            {
                                if (w[x - 20] == 0 && w[x + 3 * 19 + 3] == 0 )
                                {
                                    if ((x - 20) % 19 != 0)
                                    {
                                        if (a[x - 20] == 0)
                                        {
                                            bb(x - 20);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 - y * 1 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 19 - y * 1] == 2)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 - y * 1] != 2)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 18 >= 0 && x + 3 * 19 - 3 <= 359)
                            {
                                if (w[x - 18] == 0 && w[x + 3 * 19 - 3] == 0 )
                                {

                                    if ((x - 18) % 19 != 0)
                                    {
                                        if (a[x - 18] == 0)
                                        {
                                            bb(x - 18);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;

                }
            }







            ///判断玩家有没有还差一颗四连（堵住上半部分）*****************************************************************************************

            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    for (y = 0; y < 4; y++)
                    {
                        if (w[x] == 1)
                        {
                            if (x + y * 19 <= 360)
                            {
                                if (w[x + y * 19] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19] != 1)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 19 >= 0)
                            {
                                if (w[x - 19] == 0 && w[x + 3 * 19] == 0 )
                                {
                                    if (a[x - 19] == 0)
                                    {
                                        bb(x - 19);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 1 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 1] != 1)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 1 >= 0)
                            {
                                if (w[x - 1] == 0 && w[x + 3 * 1] == 0 )
                                {
                                    if (a[x - 1] == 0)
                                    {
                                        bb(x - 1);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 + y * 1 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 19 + y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 + y * 1] != 1)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 20 >= 0)
                            {
                                if (w[x - 20] == 0 && w[x + 3 * 19 + 3] == 0 )
                                {

                                    if ((x - 20) % 19 != 0)
                                    {
                                        if (a[x - 20] == 0)
                                        {
                                            bb(x - 20);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 4; y++)
                    {
                        if (x + y * 19 - y * 1 <= 360)
                        {
                            if (w[x] == 1)
                            {
                                if (w[x + y * 19 - y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 - y * 1] != 1)
                                {
                                    break;
                                }
                            }
                        }
                        if (z == 3)
                        {
                            if (x - 18 >= 0)
                            {
                                if (w[x - 18] == 0 && w[x + 3 * 19 - 3] == 0 )
                                {

                                    if ((x - 18) % 19 != 0)
                                    {
                                        if (a[x - 18] == 0)
                                        {
                                            bb(x - 18);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }

                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;

                }
            }



            

            //判断玩家有没有L形状*****************************

            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    if (w[x] == 0)
                    {
                        if (x + 3 <= 360)
                        {
                            if (w[x + 1] == 1)
                            {
                                if (w[x + 2] == 1)
                                {
                                    if (w[x + 3] == 0)
                                    {
                                        if (x + 19 * 3 <= 360)
                                        {
                                            if (w[x + 19 * 1] == 1)
                                            {
                                                if (w[x + 19 * 2] == 1)
                                                {
                                                    if (w[x + 19 * 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 >= 0)
                                        {
                                            if (w[x - 19 * 1] == 1)
                                            {
                                                if (w[x - 19 * 2] == 1)
                                                {
                                                    if (w[x - 19 * 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 + 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 + 1] == 1)
                                            {
                                                if (w[x + 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 - 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 - 1] == 1)
                                            {
                                                if (w[x + 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 1)
                                            {
                                                if (w[x - 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x - 19 * 2 - 2] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 1)
                                            {
                                                if (w[x - 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x + 19 * 3 <= 360)
                        {
                            if (w[x + 19 * 1] == 1)
                            {
                                if (w[x + 19 * 2] == 1)
                                {
                                    if (w[x + 19 * 3] == 0)
                                    {
                                        if (x - 19 * 3 >= 0)
                                        {
                                            if (w[x - 19 * 1] == 1)
                                            {
                                                if (w[x - 19 * 2] == 1)
                                                {
                                                    if (w[x - 19 * 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 + 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 + 1] == 1)
                                            {
                                                if (w[x + 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 - 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 - 1] == 1)
                                            {
                                                 if (w[x + 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 2 - 2 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 1)
                                            {
                                                if (w[x - 19 * 2 - 2] == 1)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 2 + 2 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 1)
                                            {
                                                if (w[x - 19 * 2 + 2] == 1)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 2 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 2 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 19 * 3 >= 0)
                        {
                            if (w[x - 19 * 1] == 1)
                            {
                                if (w[x - 19 * 2] == 1)
                                {
                                    if (w[x - 19 * 3] == 0)
                                    {
                                        if (x + 19 * 3 + 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 + 1] == 1)
                                            {
                                                if (w[x + 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 - 3 <= 360)
                                        {

                                            if (w[x + 19 * 1 - 1] == 1)
                                            {
                                                if (w[x + 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 1)
                                            {
                                                if (w[x - 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 - 3] == 0)
                                                    {

                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 1)
                                            {
                                                if (w[x - 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {

                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x + 19 * 3 + 3 <= 360)
                        {
                            if (w[x + 19 * 1 + 1] == 1)
                            {
                                if (w[x + 19 * 2 + 2] == 1)
                                {
                                    if (w[x + 19 * 3 + 3] == 0)
                                    {
                                        if (x + 19 * 3 - 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 - 1] == 1)
                                            {
                                                if (w[x + 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 1)
                                            {
                                                if (w[x - 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 1)
                                            {
                                                if (w[x - 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }

                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 1)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x + 19 * 3 - 3 <= 360)
                        {
                            if (w[x + 19 * 1 - 1] == 1)
                            {
                                if (w[x + 19 * 2 - 2] == 1)
                                {
                                    if (w[x + 19 * 3 - 3] == 0)
                                    {
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 1)
                                            {
                                                if (w[x - 19 * 2 - 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 1)
                                            {
                                                if (w[x - 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 19 * 3 - 3 >= 0)
                        {
                            if (w[x - 19 * 1 - 1] == 1)
                            {
                                if (w[x - 19 * 2 - 2] == 1)
                                {
                                    if (w[x - 19 * 3 - 3] == 1)
                                    {
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 1)
                                            {
                                                if (w[x - 19 * 2 + 2] == 1)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 19 * 3 + 3 >= 0)
                        {
                            if (w[x - 19 * 1 + 1] == 1)
                            {
                                if (w[x - 19 * 2 + 2] == 1)
                                {
                                    if (w[x - 19 * 3 + 3] == 0)
                                    {
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 1)
                                            {
                                                if (w[x - 2] == 1)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 3 >= 0)
                        {
                            if (w[x - 1] == 1)
                            {
                                if (w[x - 2] == 1)
                                {
                                    if (w[x - 3] == 0)
                                    {
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 1)
                                            {
                                                if (w[x + 2] == 1)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



            //判断AI有没有L形状*****************************

            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    if (w[x] == 0)
                    {
                        if (x + 3 <= 360)
                        {
                            if (w[x + 1] == 2)
                            {
                                if (w[x + 2] == 2)
                                {
                                    if (w[x + 3] == 0)
                                    {
                                        if (x + 19 * 3 <= 360)
                                        {
                                            if (w[x + 19 * 1] == 2)
                                            {
                                                if (w[x + 19 * 2] == 2)
                                                {
                                                    if (w[x + 19 * 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 >= 0)
                                        {
                                            if (w[x - 19 * 1] == 2)
                                            {
                                                if (w[x - 19 * 2] == 2)
                                                {
                                                    if (w[x - 19 * 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 + 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 + 1] == 2)
                                            {
                                                if (w[x + 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 - 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 - 1] == 2)
                                            {
                                                if (w[x + 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 2)
                                            {
                                                if (w[x - 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x - 19 * 2 - 2] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 2)
                                            {
                                                if (w[x - 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x + 19 * 3 <= 360)
                        {
                            if (w[x + 19 * 1] == 2)
                            {
                                if (w[x + 19 * 2] == 2)
                                {
                                    if (w[x + 19 * 3] == 0)
                                    {
                                        if (x - 19 * 3 >= 0)
                                        {
                                            if (w[x - 19 * 1] == 2)
                                            {
                                                if (w[x - 19 * 2] == 2)
                                                {
                                                    if (w[x - 19 * 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 + 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 + 1] == 2)
                                            {
                                                if (w[x + 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 - 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 - 1] == 2)
                                            {
                                                if (w[x + 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 2 - 2 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 2)
                                            {
                                                if (w[x - 19 * 2 - 2] == 2)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 2 + 2 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 2)
                                            {
                                                if (w[x - 19 * 2 + 2] == 2)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 2 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 2 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (a[x] == 0)
                                                    {
                                                        bb(x);
                                                        aisys = 1;
                                                        z = 0;
                                                        oooo = 0;
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 19 * 3 >= 0)
                        {
                            if (w[x - 19 * 1] == 2)
                            {
                                if (w[x - 19 * 2] == 2)
                                {
                                    if (w[x - 19 * 3] == 0)
                                    {
                                        if (x + 19 * 3 + 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 + 1] == 2)
                                            {
                                                if (w[x + 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 19 * 3 - 3 <= 360)
                                        {

                                            if (w[x + 19 * 1 - 1] == 2)
                                            {
                                                if (w[x + 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 2)
                                            {
                                                if (w[x - 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 - 3] == 0)
                                                    {

                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 2)
                                            {
                                                if (w[x - 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {

                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x + 19 * 3 + 3 <= 360)
                        {
                            if (w[x + 19 * 1 + 1] == 2)
                            {
                                if (w[x + 19 * 2 + 2] == 2)
                                {
                                    if (w[x + 19 * 3 + 3] == 0)
                                    {
                                        if (x + 19 * 3 - 3 <= 360)
                                        {
                                            if (w[x + 19 * 1 - 1] == 2)
                                            {
                                                if (w[x + 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x + 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 2)
                                            {
                                                if (w[x - 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 2)
                                            {
                                                if (w[x - 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }

                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 2)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x + 19 * 3 - 3 <= 360)
                        {
                            if (w[x + 19 * 1 - 1] == 2)
                            {
                                if (w[x + 19 * 2 - 2] == 2)
                                {
                                    if (w[x + 19 * 3 - 3] == 0)
                                    {
                                        if (x - 19 * 3 - 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 - 1] == 2)
                                            {
                                                if (w[x - 19 * 2 - 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 2)
                                            {
                                                if (w[x - 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 19 * 3 - 3 >= 0)
                        {
                            if (w[x - 19 * 1 - 1] == 2)
                            {
                                if (w[x - 19 * 2 - 2] == 2)
                                {
                                    if (w[x - 19 * 3 - 3] == 2)
                                    {
                                        if (x - 19 * 3 + 3 >= 0)
                                        {
                                            if (w[x - 19 * 1 + 1] == 2)
                                            {
                                                if (w[x - 19 * 2 + 2] == 2)
                                                {
                                                    if (w[x - 19 * 3 + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 19 * 3 + 3 >= 0)
                        {
                            if (w[x - 19 * 1 + 1] == 2)
                            {
                                if (w[x - 19 * 2 + 2] == 2)
                                {
                                    if (w[x - 19 * 3 + 3] == 0)
                                    {
                                        if (x - 3 >= 0)
                                        {
                                            if (w[x - 1] == 2)
                                            {
                                                if (w[x - 2] == 2)
                                                {
                                                    if (w[x - 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (x - 3 >= 0)
                        {
                            if (w[x - 1] == 2)
                            {
                                if (w[x - 2] == 2)
                                {
                                    if (w[x - 3] == 0)
                                    {
                                        if (x + 3 <= 360)
                                        {
                                            if (w[x + 1] == 2)
                                            {
                                                if (w[x + 2] == 2)
                                                {
                                                    if (w[x + 3] == 0)
                                                    {
                                                        if (a[x] == 0)
                                                        {
                                                            bb(x);
                                                            aisys = 1;
                                                            z = 0;
                                                            oooo = 0;
                                                            return;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


            //判断玩家33*****************************************************************

            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    if (w[x] == 0)
                    { 
                        
                    }
                }
            }









            //*************************************************************************************************
            //计算整个棋盘的每个位置的威胁程度，则在权重大于4的最高的地方地方落子。
            /*
            if (aisys == 0)
            {
                for (int sss = 0; sss < 361; sss++)
                {
                    if (w[sss] == 0)
                    {
                        if (sss < 341)
                        {
                            if (w[sss + 19 + 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss < 342)
                        {
                            if (w[sss + 19] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss < 343)
                        {
                            if (w[sss + 19 - 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss < 360)
                        {
                            if (w[sss + 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 2)
                        {
                            if (w[sss - 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 18)
                        {
                            if (w[sss - 19 + 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 19)
                        {
                            if (w[sss - 19] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 20)
                        {
                            if (w[sss - 19 - 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                    }
                }
                int[] wz = new int[361];
                index = aiiq[0];
                for (int sss = 0; sss < 361; sss++)
                {
                    if (index <= aiiq[sss])
                    {
                        index = aiiq[sss];
                        t = sss;
                    }
                }
                zd = t;
                if (aiiq[t] >= 4)
                {
                    if (a[t] == 0)
                    {
                        button[t].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                        a[t] = 1;
                        w[t] = 2;
                        aisys = 0;
                        for (int plm = 0; plm < 361; plm++)
                        {
                            aiiq[plm] = 0;
                        }
                        return;
                    }
                    for (int plm = 0; plm < 361; plm++)
                    {
                        aiiq[plm] = 0;
                    }
                }
                for (int plm = 0; plm < 361; plm++)
                {
                    aiiq[plm] = 0;
                }
            }



            */















            //判断玩家有没有0.0形式=======================================************************************
            if (aisys == 0)
            {
                for (x = 0; x < 360; x++)
                {
                    for (y = 0; y < 3; y++)
                    {
                        if (x + 2 * 19 <= 360)
                        {
                            if (w[x] == 1 && w[x + 2 * 19] == 1)
                            {
                                if (w[x + y * 19] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19] == 0)
                                {
                                    oooo = x + y * 19;
                                }
                            }
                        }

                        if (z == 1)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 19] == 0 && w[x - 19] == 0)
                                {
                                    if (x + 3 * 19 <= 360 && x - 19 >= 0)
                                    {
                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 3; y++)
                    {
                        if (x + 2 * 1 <= 360)
                        {
                            if (w[x] == 1 && w[x + 2 * 1] == 1)
                            {
                                if (w[x + y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 1] == 0)
                                {
                                    oooo = x + y * 1;
                                }
                            }
                        }

                        if (z == 1)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 1] == 0 && w[x - 1] == 0)
                                {
                                    if (x + 3 * 1 <= 360 && x - 1 >= 0)
                                    {
                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;




                    for (y = 0; y < 3; y++)
                    {
                        if (x + 2 * 19 + 2 * 1 <= 360)
                        {
                            if (w[x] == 1 && w[x + 2 * 19 + 2 * 1] == 1)
                            {
                                if (w[x + y * 19 + y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 + y * 1] == 0)
                                {
                                    oooo = x + y * 19 + y * 1;
                                }
                            }
                        }

                        if (z == 1)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 19 + 3 * 1] == 0 && w[x - 20] == 0)
                                {
                                    if (x + 3 * 19 + 3 * 1 <= 360 && x - 20 >= 0)
                                    {
                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;



                    for (y = 0; y < 2; y++)
                    {
                        if (x + 2 * 19 - 2 * 1 <= 360)
                        {
                            if (w[x] == 1 && w[x + 2 * 19 - 2 * 1] == 1)
                            {
                                if (w[x + y * 19 - y * 1] == 1)
                                {
                                    z += 1;
                                }
                                if (w[x + y * 19 - y * 1] == 0)
                                {
                                    oooo = x + y * 19 - y * 1;
                                }
                            }
                        }

                        if (z == 1)
                        {
                            if (oooo != 0)
                            {
                                if (w[x + 3 * 19 - 3 * 1] == 0 && w[x - 18] == 0)
                                {
                                    if (x + 3 * 19 - 3 * 1 <= 360 && x - 18 >= 0)
                                    {

                                        if (a[oooo] == 0)
                                        {
                                            bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    z = 0;
                    oooo = 0;

                }
            }










            ///判断AI有没有2连可以达成5连的*****************************************************************************************


            for (x = 0; x < 360; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x + (y * 19) <= 360)
                    {
                        if (w[x] != 1)
                        {
                            if (w[x + y * 19] == 0)
                            {
                                if (x + y * 19 - 19 >= 0)
                                {
                                    if (w[x + y * 19 - 19] == 2)
                                    {
                                        if (w[x + y * 19] == 0)
                                        {
                                            oooo = x + y * 19;
                                        }
                                    }
                                }
                                if (x + y * 19 + 19 <= 360)
                                {
                                    if (w[x + y * 19 + 19] == 2)
                                    {
                                        if (w[x + y * 19] == 0)
                                        {
                                            oooo = x + y * 19;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 19] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }                          
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;


                for (y = 0; y < 5; y++)
                {
                    if (x + x * 1 <= 360)
                    {
                        if (w[x] != 1)
                        {
                            if (w[x + y * 1] == 0)
                            {
                                if (x + y * 1 - 1 >= 0)
                                {
                                    if (w[x + y * 1 - 1] == 2)
                                    {
                                        if (w[x + y * 1] == 0)
                                        {
                                            oooo = x + y * 1;
                                        }
                                    }
                                }
                                if (x + y * 1 + 1 <= 360)
                                {
                                    if (w[x + y * 1 + 1] == 2)
                                    {
                                        if (w[x + y * 1] == 0)
                                        {
                                            oooo = x + y * 1;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;



                for (y = 0; y < 5; y++)
                {
                    if (x + (y + 1) * 19 + (y + 1) * 1 <= 360)
                    {
                        if (w[x] != 1)
                        {
                            if (w[x + y * 19 + y * 1] == 0)
                            {
                                if (x + (y - 1) * 19 + (y - 1) * 1 >= 0)
                                {
                                    if (w[x + (y - 1) * 19 + (y - 1) * 1] == 2)
                                    {
                                        if (w[x + y * 19 + y * 1] == 0)
                                        {
                                            oooo = x + y * 19 + y * 1;
                                        }
                                    }
                                }
                                if (x + (y + 1) * 19 + (y + 1) * 1 <= 360)
                                {
                                    if (w[x + (y + 1) * 19 + (y + 1) * 1] == 2)
                                    {
                                        if (w[x + y * 19 + y * 1] == 0)
                                        {
                                            oooo = x + y * 19 + y * 1;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }

                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;




                for (y = 0; y < 5; y++)
                {
                    if (x + (y + 1) * 19 - (y + 1) * 1 <= 360)
                    {
                        if (w[x] != 1)
                        {
                            if (w[x + y * 19 - y * 1] == 0)
                            {
                                if (x + (y - 1) * 19 - (y - 1) * 1 >= 0)
                                {
                                    if (w[x + (y - 1) * 19 - (y - 1) * 1] == 2)
                                    {
                                        if (w[x + y * 19 - y * 1] == 0)
                                        {
                                            oooo = x + y * 19 - y * 1;
                                        }
                                    }
                                }
                                if (x + (y + 1) * 19 - (y + 1) * 1 <= 360)
                                {
                                    if (w[x + (y + 1) * 19 - (y + 1) * 1] == 2)
                                    {
                                        if (w[x + y * 19 + y * 1] == 0)
                                        {
                                            oooo = x + y * 19 + y * 1;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }

                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;
            }

          




            //以上条件都没满足，在自己一颗的基础上落子===========================================
            for (x = 0; x < 360; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x + (y * 19) <= 360)
                    {
                        if (w[x] == 2)
                        {
                            if (w[x + y * 19] == 0)
                            {
                                oooo = x + y * 19;
                                ls += 1;
                            }
                            if (w[x + y * 19] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 1 && ls == 4)
                    {
                        if (x - 19 >= 0)
                        {
                            if (w[x - 19] == 0)
                            {
                                if (a[x - 19] == 0)
                                {
                                    bb(x - 19);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                        if (x + 19 <= 360)
                        {
                            if (w[x + 19] == 0)
                            {
                                if (a[x + 19] == 0)
                                {
                                    bb(x + 19);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;


                for (y = 0; y < 5; y++)
                {
                    if (x + x * 1 <= 360)
                    {
                        if (w[x] == 2)
                        {
                            if ((x + y * 1) % 19 == 0)
                            {
                                break;
                            }
                            if (w[x + y * 1] == 0)
                            {
                                oooo = x + y * 1;
                                ls += 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 1 && ls == 4)
                    {
                        if (a[x - 1] == 0)
                        {
                            if (w[x - 1] == 0)
                            {
                                bb(x - 1);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;
                            }
                        }
                        if (a[x + 1] == 0)
                        {
                            if (w[x + 1] == 0)
                            {
                                bb(x + 1);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;

                for (y = 0; y < 5; y++)
                {
                    if (w[x] == 2)
                    {
                        if (x + (y * 19 + y * 1) <= 360)
                        {
                            if ((x + y * 19 + y * 1) % 19 == 0)
                            {
                                break;
                            }
                            if (w[x + y * 19 + y * 1] == 0)
                            {
                                oooo = x + y * 19 + y * 1;
                                ls += 1;
                            }
                            if (w[x + y * 19 + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 1 && ls == 4)
                    {
                        if (w[x - 20] == 0)
                        {
                            if (a[x - 20] == 0)
                            {
                                bb(x - 20);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;
                            }
                        }
                        if (w[x + 20] == 0)
                        {
                            if (a[x + 20] == 0)
                            {
                                bb(x + 20);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;


                for (y = 0; y < 5; y++)
                {
                    if (w[x] == 2)
                    {
                        if (x + (y * 19 - y * 1) <= 360)
                        {
                            if ((x + y * 19 - y * 1) + 1 % 19 == 0)
                            {
                                break;
                            }
                            if (w[x + y * 19 - y * 1] == 0)
                            {
                                oooo = x + y * 19 - y * 1;
                                ls += 1;
                            }
                            if (w[x + y * 19 - y * 1] == 2)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 1 && ls == 4)
                    {
                        if (w[x - 18] == 0)
                        {
                            if (a[x - 18] == 0)
                            {
                                bb(x - 18);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;
                            }
                        }
                        if (w[x + 18] == 0)
                        {
                            if (a[x + 18] == 0)
                            {
                                bb(x + 18);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;
            }



            ///判断AI有没有2连可以达成5连的*****************************************************************************************


            for (x = 0; x < 360; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x + (y * 19) <= 360)
                    {
                        if (w[x] != 2)
                        {
                            if (w[x + y * 19] == 0)
                            {
                                if (x + y * 19 - 19 >= 0)
                                {
                                    if (w[x + y * 19 - 19] == 1)
                                    {
                                        if (w[x + y * 19] == 0)
                                        {
                                            oooo = x + y * 19;
                                        }
                                    }
                                }
                                if (x + y * 19 + 19 <= 360)
                                {
                                    if (w[x + y * 19 + 19] == 1)
                                    {
                                        if (w[x + y * 19] == 0)
                                        {
                                            oooo = x + y * 19;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 19] == 1)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;


                for (y = 0; y < 5; y++)
                {
                    if (x + x * 1 <= 360)
                    {
                        if (w[x] != 2)
                        {
                            if (w[x + y * 1] == 0)
                            {
                                if (x + y * 1 - 1 >= 0)
                                {
                                    if (w[x + y * 1 - 1] == 1)
                                    {
                                        if (w[x + y * 1] == 0)
                                        {
                                            oooo = x + y * 1;
                                        }
                                    }
                                }
                                if (x + y * 1 + 1 <= 360)
                                {
                                    if (w[x + y * 1 + 1] == 1)
                                    {
                                        if (w[x + y * 1] == 0)
                                        {
                                            oooo = x + y * 1;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 1] == 4)
                            {
                                z += 1;
                            }
                        }
                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;



                for (y = 0; y < 5; y++)
                {
                    if (x + (y + 1) * 19 + (y + 1) * 1 <= 360)
                    {
                        if (w[x] != 2)
                        {
                            if (w[x + y * 19 + y * 1] == 0)
                            {
                                if (x + (y - 1) * 19 + (y - 1) * 1 >= 0)
                                {
                                    if (w[x + (y - 1) * 19 + (y - 1) * 1] == 1)
                                    {
                                        if (w[x + y * 19 + y * 1] == 0)
                                        {
                                            oooo = x + y * 19 + y * 1;
                                        }
                                    }
                                }
                                if (x + (y + 1) * 19 + (y + 1) * 1 <= 360)
                                {
                                    if (w[x + (y + 1) * 19 + (y + 1) * 1] == 1)
                                    {
                                        if (w[x + y * 19 + y * 1] == 0)
                                        {
                                            oooo = x + y * 19 + y * 1;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }

                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;




                for (y = 0; y < 5; y++)
                {
                    if (x + (y + 1) * 19 - (y + 1) * 1 <= 360)
                    {
                        if (w[x] != 2)
                        {
                            if (w[x + y * 19 - y * 1] == 0)
                            {
                                if (x + (y - 1) * 19 - (y - 1) * 1 >= 0)
                                {
                                    if (w[x + (y - 1) * 19 - (y - 1) * 1] == 1)
                                    {
                                        if (w[x + y * 19 - y * 1] == 0)
                                        {
                                            oooo = x + y * 19 - y * 1;
                                        }
                                    }
                                }
                                if (x + (y + 1) * 19 - (y + 1) * 1 <= 360)
                                {
                                    if (w[x + (y + 1) * 19 - (y + 1) * 1] == 1)
                                    {
                                        if (w[x + y * 19 + y * 1] == 0)
                                        {
                                            oooo = x + y * 19 + y * 1;
                                        }
                                    }
                                }
                                ls += 1;
                            }
                            if (w[x + y * 1] == 2)
                            {
                                z += 1;
                            }
                        }

                    }
                    if (z == 2 && ls == 3)
                    {
                        if (oooo != 0)
                        {
                            if (w[oooo] == 0)
                            {
                                if (a[oooo] == 0)
                                {
                                    bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;
            }








            //*************************************************************************************************
            //计算整个棋盘的每个位置的威胁程度，如果上述条件都没达成，则在权重最高的地方落子。
            if (aisys == 0)
            {
                for (int sss = 0; sss < 361; sss++)
                {
                    if (w[sss] == 0)
                    {
                        if (sss < 341)
                        {
                            if (w[sss + 19 + 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss < 342)
                        {
                            if (w[sss + 19] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss < 343)
                        {
                            if (w[sss + 19 - 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss < 360)
                        {
                            if (w[sss + 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 2)
                        {
                            if (w[sss - 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 18)
                        {
                            if (w[sss - 19 + 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 19)
                        {
                            if (w[sss - 19] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                        if (sss >= 20)
                        {
                            if (w[sss - 19 - 1] == 1)
                            {
                                aiiq[sss] += 1;
                            }
                        }
                    }
                }
                int[] wz = new int[361];
                index = aiiq[0];
                for (int sss = 0; sss < 361; sss++)
                {
                    if (index <= aiiq[sss])
                    {
                        index = aiiq[sss];
                        t = sss;
                    }
                }
                zd = t;
                if (aiiq[t] >= 1)
                {
                    if (a[t] == 0)
                    {
                        button[t].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                        a[t] = 1;
                        w[t] = 2;
                        aisys = 0;
                    }
                    for (int plm = 0; plm < 361; plm++)
                    {
                        aiiq[plm] = 0;
                    }
                }
            }
        }

        /*



        //*****************************************
        //ai判断有没有己方四连子
        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {
                        if (w[x + y * 19] == 0)
                        {
                            oooo = x + y * 19;
                        }
                        if (w[x + y * 19] == 2)
                        {
                            z += 1;
                        }
                        if (z == 4 && oooo != 0)
                        {
                            if(a[oooo]==0){bb(oooo);
                            aisys = 1;
                            z = 0;
                            oooo = 0;
                            return;}
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 355)
                    {
                        if (w[x + y * 1] == 0)
                        {
                            oooo = x + y * 1;
                        }
                        if (w[x + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (x > 0)
                            {
                                if (z == 4 && oooo != 0)
                                {
                                    if(a[oooo]==0){bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 255)
                    {

                        if (w[x + y * 19 + y * 1] == 0)
                        {
                            oooo = x + y * 19 + y * 1;
                        }
                        if (w[x + y * 19 + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 + y * 1)  % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (z == 4 && oooo != 0)
                            {
                                if(a[oooo]==0){bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;}
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {

                        if (w[x + y * 19 - y * 1] == 0)
                        {
                            oooo = x + y * 19 - y * 1;
                        }
                        if (w[x + y * 19 - y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 - y * 1) + 1 % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (x >= 10)
                            {
                                if (z == 4)
                                {
                                    if (z == 4 && oooo != 0)
                                    {
                                        if(a[oooo]==0){bb(oooo);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;}
                                    }
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
            }
        }




        //************************************
        //判断00.00格式

        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {
                        if (w[x + y * 19] == 0)
                        {
                            oooo = x + y * 19;
                        }
                        if (w[x + y * 19] == 2)
                        {
                            z += 1;
                        }
                        if (z == 4 && oooo != 0)
                        {
                            if(a[oooo]==0){bb(oooo);
                            aisys = 1;
                            z = 0;
                            oooo = 0;
                            return;}
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 355)
                    {
                        if (w[x + y * 1] == 0)
                        {
                            oooo = x + y * 1;
                        }
                        if (w[x + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (x > 0)
                            {
                                if (z == 4 && oooo != 0)
                                {
                                    if(a[oooo]==0){bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 255)
                    {

                        if (w[x + y * 19 + y * 1] == 0)
                        {
                            oooo = x + y * 19 + y * 1;
                        }
                        else if (w[x + y * 19 + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;

                        }
                        if (z == 4)
                        {
                            if (z == 4 && oooo != 0)
                            {
                                if(a[oooo]==0){bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;}
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {

                        if (w[x + y * 19 - y * 1] == 0)
                        {
                            oooo = x + y * 19 - y * 1;
                        }
                        else if (w[x + y * 19 - y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 - y * 1) + 1 % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (x >= 10)
                            {
                                if (z == 4)
                                {
                                    if (z == 4 && oooo != 0)
                                    {
                                        if(a[oooo]==0){bb(oooo);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;}
                                    }
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
            }
        }




          


        //*******************************************************************
        //ai判断对方有没有四连子
        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {
                        if (w[x + y * 19] == 0)
                        {
                            oooo = x + y * 19;
                        }
                        if (w[x + y * 19] == 1)
                        {
                            z += 1;
                        }
                        if (z == 4 && oooo != 0)
                        {
                            if(a[oooo]==0){bb(oooo);
                            aisys = 1;
                            z = 0;
                            oooo = 0;
                            return;}
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 355)
                    {
                        if (w[x + y * 1] == 0)
                        {
                            oooo = x + y * 1;
                        }
                        if (w[x + y * 1] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (x > 0)
                            {
                                if (z == 4 && oooo != 0)
                                {
                                    if(a[oooo]==0){bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 255)
                    {

                        if (w[x + y * 19 + y * 1] == 0)
                        {
                            oooo = x + y * 19 + y * 1;
                        }
                        else if (w[x + y * 19 + y * 1] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;

                        }
                        if (z == 4)
                        {
                            if (z == 4 && oooo != 0)
                            {
                                if(a[oooo]==0){bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;}
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {

                        if (w[x + y * 19 - y * 1] == 0)
                        {
                            oooo = x + y * 19 - y * 1;
                        }
                        else if (w[x + y * 19 - y * 1] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 - y * 1) + 1 % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 4)
                        {
                            if (x >= 10)
                            {
                                if (z == 4)
                                {
                                    if (z == 4 && oooo != 0)
                                    {
                                        if(a[oooo]==0){bb(oooo);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;}
                                    }
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
            }
        }

        //************************************
        //判断0.00格式

        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y < 4; y++)
                {
                    if (x < 303)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 19] == 0)
                            {
                                ls = x + y * 19;
                            }
                        }
                        if (w[x + y * 19] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (x > 0)
                            {
                                if (z == 3 && ls != 0)
                                {
                                    bb(ls);
                                    aisys = 1;
                                    z = 0;
                                    ls = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;
                for (y = 0; y < 4; y++)
                {
                    if (x < 355)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 1] == 0)
                            {
                                ls = x + y * 1;
                            }
                        }
                        if (w[x + y * 1] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (x > 0)
                            {
                                if (z == 3 && ls != 0)
                                {
                                    bb(ls);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    ls = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;
                for (y = 0; y < 4; y++)
                {
                    if (x < 255)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 19 + y * 1] == 0)
                            {
                                ls = x + y * 19 + y * 1;
                            }
                        }
                        if (w[x + y * 19 + y * 1] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (z == 3 && ls != 0)
                            {
                                bb(ls);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                ls = 0;
                                return;}
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls = 0;
                for (y = 0; y < 5; y++)
                {
                    if (x < 265)
                    {
                        if (w[x] == 1)
                        {
                            if (w[x + y * 19 - y * 1] == 0)
                            {
                                ls = x + y * 19 - y * 1;
                            }
                        }
                        if (w[x + y * 19 - y * 1] == 1)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 - y * 1) + 1 % 19 == 0 && x - 1 % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (x >= 10)
                            {
                                if (z == 3)
                                {
                                    if (z == 3 && ls != 0)
                                    {
                                        bb(ls);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        ls=0;
                                        return;}
                                    }
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                ls=0;
            }
        }



 

                //***********************************************
                //判断对方有没有三连子（判断后一半）
               if (aisys == 0)
                {
                    for (x = 0; x < 361; x++)
                    {
                        for (y = 0; y < 3; y++)
                        {
                            if (x < 265)
                            {
                                if (w[x + y * 19] == 1)
                                {
                                    z += 1;
                                }
                                if (z == 3 )
                                {
                                    oooo = x + (y + 1) * 19;
                                    if (w[oooo] == 0)
                                    {
                                            
                                        if(a[oooo]==0){bb(oooo);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;}
                                    }
                                }
                            }
                        }
                        z = 0;
                        oooo = 0;
                        for (y = 0; y < 3; y++)
                        {
                            if (x < 355)
                            {
                                if (w[x + y * 1] == 0)
                                {
                                    oooo = x + y * 1;
                                }
                                if (w[x + y * 1] == 1)
                                {
                                    if (y == 0)
                                    {
                                        if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                        {
                                            break;
                                        }
                                    }
                                    z += 1;
                                }
                                if (z == 3)
                                {
                                    if (x > 0)
                                    {
                                        if (z == 3 && oooo != 0)
                                        {
                                            if (w[oooo] == 0)
                                            {
                                                if(a[oooo]==0){bb(oooo);
                                                aisys = 1;
                                                z = 0;
                                                oooo = 0;
                                                return;}
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        z = 0;
                        oooo = 0;
                        for (y = 0; y < 3; y++)
                        {
                            if (x < 255)
                            {

                                if (w[x + y * 19 + y * 1] == 0)
                                {
                                    oooo = x + y * 19 + y * 1;
                                }
                                if (w[x + y * 19 + y * 1] == 1)
                                {
                                    if (y == 0)
                                    {
                                        if ((x + y * 19 + y * 1) % 19 == 0 && x % 19 != 0)
                                        {
                                            break;
                                        }
                                    }
                                    z += 1;
                                }
                                if (z == 3)
                                {
                                    if (z == 3 && oooo != 0)
                                    {
                                        if (w[oooo] == 0)
                                        {
                                            if(a[oooo]==0){bb(oooo);
                                            aisys = 1;
                                            z = 0;
                                            oooo = 0;
                                            return;}
                                        }
                                    }
                                }
                            }
                        }
                        z = 0;
                        oooo = 0;
                        for (y = 0; y < 3; y++)
                        {
                            if (x < 265)
                            {

                                if (w[x + y * 19 - y * 1] == 0)
                                {
                                    oooo = x + y * 19 - y * 1;
                                }
                                if (w[x + y * 19 - y * 1] == 1)
                                {
                                    if (y == 0)
                                    {
                                        if ((x + y * 19 - y * 1) % 19 == 0 && x % 19 != 0)
                                        {
                                            break;
                                        }
                                    }
                                    z += 1;
                                }
                                if (z == 3)
                                {
                                    if (x >= 10)
                                    {
                                        if (z == 3)
                                        {
                                            if (z == 3 && oooo != 0)
                                            {
                                                if (w[oooo] == 0)
                                                {
                                                    if(a[oooo]==0){bb(oooo);
                                                    aisys = 1;
                                                    z = 0;
                                                    oooo = 0;
                                                    return;}
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        z = 0;
                        oooo = 0;
                    }
                }
        
        //*******************************************************
        //判断自己有没有三连子


        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y < 4; y++)
                {
                    if (x < 265)
                    {
                        if (w[x + y * 19] == 0)
                        {
                            oooo = x + y * 19;
                        }
                        if (w[x + y * 19] == 2)
                        {
                            z += 1;
                        }
                        if (z == 3 && oooo != 0)
                        {
                            if(a[oooo]==0){bb(oooo);
                            aisys = 1;
                            z = 0;
                            oooo = 0;
                            return;}
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 4; y++)
                {
                    if (x < 355)
                    {
                        if (w[x + y * 1] == 0)
                        {
                            oooo = x + y * 1;
                        }
                        if (w[x + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (x > 0)
                            {
                                if (z == 3 && oooo != 0)
                                {
                                    if(a[oooo]==0){bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 4; y++)
                {
                    if (x < 255)
                    {

                        if (w[x + y * 19 + y * 1] == 0)
                        {
                            oooo = x + y * 19 + y * 1;
                        }
                        if (w[x + y * 19 + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (z == 3 && oooo != 0)
                            {
                                if(a[oooo]==0){bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;}
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 4; y++)
                {
                    if (x < 265)
                    {

                        if (w[x + y * 19 - y * 1] == 0)
                        {
                            oooo = x + y * 19 - y * 1;
                        }
                        if (w[x + y * 19 - y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 - y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 3)
                        {
                            if (x >= 10)
                            {
                                if (z == 3)
                                {
                                    if (z == 3 && oooo != 0)
                                    {
                                        if(a[oooo]==0){bb(oooo);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;}
                                    }
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
            }
        }


        //*************************************
        //判断自己2连
        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y < 3; y++)
                {
                    if (x < 265)
                    {
                        if (w[x + y * 19] == 0)
                        {
                            oooo = x + y * 19;
                        }
                        if (w[x + y * 19] == 2)
                        {
                            z += 1;
                        }
                        if (z == 2 && oooo != 0)
                        {
                            if(a[oooo]==0){bb(oooo);
                            aisys = 1;
                            z = 0;
                            oooo = 0;
                            return;}
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 3; y++)
                {
                    if (x < 355)
                    {
                        if (w[x + y * 1] == 0)
                        {
                            oooo = x + y * 1;
                        }
                        if (w[x + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 2)
                        {
                            if (x > 0)
                            {
                                if (z == 2 && oooo != 0)
                                {
                                    if(a[oooo]==0){bb(oooo);
                                    aisys = 1;
                                    z = 0;
                                    oooo = 0;
                                    return;}
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 3; y++)
                {
                    if (x < 255)
                    {

                        if (w[x + y * 19 + y * 1] == 0)
                        {
                            oooo = x + y * 19 + y * 1;
                        }
                        if (w[x + y * 19 + y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 + y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 2)
                        {
                            if (z == 2 && oooo != 0)
                            {
                                if(a[oooo]==0){bb(oooo);
                                aisys = 1;
                                z = 0;
                                oooo = 0;
                                return;}
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
                for (y = 0; y < 3; y++)
                {
                    if (x < 265)
                    {

                        if (w[x + y * 19 - y * 1] == 0)
                        {
                            oooo = x + y * 19 - y * 1;
                        }
                        if (w[x + y * 19 - y * 1] == 2)
                        {
                            if (y == 0)
                            {
                                if ((x + y * 19 - y * 1) % 19 == 0 && x % 19 != 0)
                                {
                                    break;
                                }
                            }
                            z += 1;
                        }
                        if (z == 2)
                        {
                            if (x >= 10)
                            {
                                if (z == 2)
                                {
                                    if (z == 2 && oooo != 0)
                                    {
                                        if(a[oooo]==0){bb(oooo);
                                        aisys = 1;
                                        z = 0;
                                        oooo = 0;
                                        return;}
                                    }
                                }
                            }
                        }
                    }
                }
                z = 0;
                oooo = 0;
            }
        }



            
                    //************************
                    //没有威胁时在自己旁边下棋
        if (aisys == 0)
        {
            for (x = 0; x < 361; x++)
            {
                if (x < 341)
                {
                    if (w[x] == 2)
                    {
                        if (w[x + 19] == 0)
                        {
                            bb(x + 19);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                if (x > 19)
                {
                    if (w[x] == 2)
                    {
                        if (w[x - 19] == 0)
                        {
                            bb(x - 19);
                            aisys = 1;
                            return;}
                        }
                    }
                }

                if (x < 360)
                {
                    if (w[x] == 2)
                    {
                        if (w[x + 1] == 0)
                        {
                            bb(x + 1);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                if (x > 1)
                {
                    if (w[x] == 2)
                    {
                        if (w[x - 1] == 0)
                        {
                            bb(x - 1);
                            aisys = 1;
                            return;}
                        }
                    }
                }

                if (x < 340)
                {
                    if (w[x] == 2)
                    {
                        if (w[x + 20] == 0)
                        {
                            bb(x + 20);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                if (x > 20)
                {
                    if (w[x] == 2)
                    {
                        if (w[x - 20] == 0)
                        {
                            bb(x - 20);
                            aisys = 1;
                            return;}
                        }
                    }
                }

                if (x < 342)
                {
                    if (w[x] == 2)
                    {
                        if (w[x + 18] == 0)
                        {
                            bb(x + 18);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                if (x > 18)
                {
                    if (w[x] == 2)
                    {
                        if (w[x - 18] == 0)
                        {
                            bb(x - 18);
                            aisys = 1;
                            return;}
                        }
                    }
                }
            }
        }
           
    }
    */

        //***************************************************
        /*
        if (aisys == 0)
        {
               
            for (x = 0; x < 361; x++)
            {
                if (w[x] == 1)
                {
                    if (x <= 341)
                    {
                        if (w[x + 19] == 0)
                        {
                            bb(x + 19);
                            aisys = 1;
                            return;}
                        }
                    }
                    if (x >= 19)
                    {
                        if (w[x - 19] == 0)
                        {
                            bb(x - 19);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                z = 0;
                if (w[x] == 1)
                {
                    if (x <= 359)
                    {
                        if (w[x + 1] == 0)
                        {
                            bb(x + 1);
                            aisys = 1;
                            return;}
                        }
                    }
                    if (x >= 1)
                    {
                        if (w[x - 1] == 0)
                        {
                            bb(x - 1);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                z = 0;
                if (w[x] == 1)
                    if (w[x] == 1)
                    {
                        if (x <= 340)
                        {
                            if (w[x + 20] == 0)
                            {
                                bb(x + 20);
                                aisys = 1;
                                return;}
                            }
                        }
                        if (x >= 20)
                        {
                            if (w[x - 20] == 0)
                            {
                                bb(x - 20);
                                aisys = 1;
                                return;}
                            }
                        }
                    }
                z = 0;
                if (w[x] == 1)
                {
                    if (x <= 342)
                    {
                        if (w[x + 18] == 0)
                        {
                            bb(x + 18);
                            aisys = 1;
                            return;}
                        }
                    }
                    if (x >= 20)
                    {
                        if (w[x - 20] == 0)
                        {
                            bb(x - 20);
                            aisys = 1;
                            return;}
                        }
                    }
                }
                z = 0;
            }
        }

    }
        */


        /*
            
        int x = 0, y = 0, z = 0;
        for (x = 0; x < 361; x++)
        {
            for (y = 0; y <5; y++)
            {
                if (x < 266)
                {
                    if (w[x + y * 19] == 1)
                    {
                        z = z + 1;
                        if (z >= 3)
                        {
                            if (x >= 19)
                            {
                                if (w[x - 19] == 0)
                                {
                                    button[x + 19].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                                    a[x + 19] = 1;
                                    w[x + 19] = 2;
                                    return;}
                                }
                                    
                            }
                        }
                    }
                }
            }
            z = 0;
        }
    }
         * */
        /*
        if (x >= 19)
        {
            if (w[x + (y + 1) * 19] != 1 && w[x + (y + 1) * 19] != 2)
            {
                button[x + (y + 1) * 19].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                a[x + (y + 1) * 19] = 1;
                w[x + (y + 1) * 19] = 2;
                return;}
            }
        }
        if (x <= 265)
        {
            if (w[x + (y + 2) * 19] != 1 && w[x + (y + 2) * 19] != 2)
            {
                button[x + (y + 2) * 19].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                a[x + (y + 2) * 19] = 1;
                w[x + (y + 2) * 19] = 2;
                return;}
            }
        }
         * 
                              
           
*/
        /*
        Random example = new Random();//ai第一步的随机落子坐标
        aisys = example.Next(1, 361);//int ai=1-361随机一个
        if (aidyb == 0)
        {
            if (w[aisys] != 1)
            {
                aidyb = 1;
                button[aisys].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                a[aisys] = 1;
                w[aisys] = 2;
                aidyb = 1;
            }
            else
            {
                for (int abc = 0; abc < 361; abc++)
                {
                    if (w[abc] != 1)
                    {
                        aidyb = 1;
                        button[aisys + 1].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                        a[aisys + 1] = 1;
                        w[aisys + 1] = 2;
                    }
                }
            }
          }
         * */
        /*
        for (int sss = 0; sss < 361; sss++)
        {
            if (sss < 341)
            {
                if (w[sss + 19 + 1] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss < 342)
            {
                if (w[sss + 19] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss < 343)
            {
                if (w[sss + 19 - 1] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss < 360)
            {
                if (w[sss + 1] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss >= 2)
            {
                if (w[sss - 1] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss >= 18)
            {
                if (w[sss - 19 + 1] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss >= 19)
            {
                if (w[sss - 19] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
            if (sss >= 20)
            {
                if (w[sss - 19 - 1] == 1)
                {
                    aiiq[sss] += 1;
                }
            }
                
        }

          
        /* 
        if (w[index] == 0)
        {
            button[index].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
            a[index] = 1;
            w[index] = 2;
        }
              
        else if (w[index] != 0)
        {
            for (int asdfg = 0; asdfg < 361; asdfg++)
            {
                if (aiiq[asdfg] != 0)
                {
                    if (a[index1] != 0)
                    {
                        break;
                    }
                    else if (a[index1] == 0)
                    {
                        button[index1].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                        a[index1] = 1;
                        w[index1] = 2;
                        break;
                    }
                }
            }
            label7.Text = Convert.ToString(aiiq[index1]);
        }            
        int poi=0;
        if(poi==1)
        {}
        else
        {
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y <= 5; y++)
                {
                    if (x < 266)
                    {
                        if (w[x + y * 19] == 1)
                        {
                            z += 1;
                            label7.Text = Convert.ToString(aiiq[x]);
                            if (z == 3)
                            {
                                if (w[x - 19] == 0)
                                {
                                    button[w[x - 19]].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                                    a[x - 19] = 1;
                                    w[x - 19] = 2;
                                    z = 0;
                                    break;
                                }
                                if (w[x - 19] != 0)
                                {
                                    if (w[x + (y + 1) * 19] == 0)
                                    {
                                        button[w[x + (y + 1) * 19]].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                                        a[x + (y + 1) * 19] = 1;
                                        w[x + (y + 1) * 19] = 2;
                                        z = 0;
                                        break;
                                    }
                                    else if (w[x + (y + 1) * 19] == 2)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (z == 4)
                            {
                                if (w[x - 19] == 0)
                                {
                                    button[w[x - 19]].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                                    a[x - 19] = 1;
                                    w[x - 19] = 2;
                                    z = 0;
                                    break;
                                }
                                else if (w[x - 19] != 0)
                                {
                                    if (w[x + (y + 1) * 19] == 0)
                                    {
                                        button[w[x + (y + 1) * 19]].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
                                        a[x + (y + 1) * 19] = 1;
                                        w[x + (y + 1) * 19] = 2;
                                        z = 0;
                                        break;
                                    }
                                    else if (w[x + (y + 1) * 19] == 2)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
            }
        }
        for (int wagasga = 0; wagasga < 361; wagasga++)
        {
            aiiq[wagasga] = 0;

        }
    }
        
     *
            
     * 
else
{
    for (int abc = 0; abc < 361; abc++)
    {
        if (w[abc] != 1)
        {
            button[aisys].BackgroundImage = Image.FromFile(@"imgdata\白棋.jpg");
            a[aisys + 1] = 1;
            w[aisys + 1] = 2;
        }
    }
}
     * */


        private void button1_Click(object sender, EventArgs e)//判定
        {
            Thread.Sleep(2000);
            System.Windows.Forms.Button bt = (System.Windows.Forms.Button)sender;
            int index = bt.TabIndex;//通过这个按钮的TabIndex确定他是第几个按钮
            if (m == 0)
            {
                if (a[index] == 0)
                {
                    hq += 1; yg += 1;
                    label6.Text = Convert.ToString(yg);
                    label5.Text = Convert.ToString(bq);
                    label4.Text = Convert.ToString(hq);
                    System.Windows.Forms.Button beforebut = button[index];//点击的按钮
                    if (a[index] == 0)
                    {
                        button[index].BackgroundImage = Image.FromFile(@"imgdata\黑棋.jpg");
                        a[index] = 1;
                        w[index] = 1;
                        m = 1;
                        win(index);
                        //if (a[index] != 1)
                        ai(index);
                        win(index);
                        m = 0;
                    }
                }
            }
        }
        void win(int a)
        {
            int x = 0, y = 0, z = 0;
            for (x = 0; x < 361; x++)
            {
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 19 <= 360)
                    {
                        if (w[x + y * 19] == 1)
                        {
                            z += 1;
                            if (z == 5)
                            {
                                z = 0;
                                ok();
                                
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 19 <= 360)
                    {
                        if (w[x + y * 19] == 2)
                        {
                            z += 1;
                            if (z == 5)
                            {
                                z = 0;
                                no();
                                

                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 1 <= 360)
                    {
                        if (w[x + y * 1] == 1)
                        {
                            z += 1;
                            if ((x + y * 1) % 19 == 0)
                            {
                                if (z == 5)
                                {
                                    z = 0;
                                    
                                    ok();
                                }
                                break;
                            }
                            else if (z == 5)
                            {
                                z = 0;
                                
                                ok();
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 1 <= 360)
                    {
                        if (w[x + y * 1] == 2)
                        {
                            z += 1;
                            if ((x + y * 1) % 19 == 0)
                            {
                                if (z == 5)
                                {
                                    z = 0;
                                    
                                    no();
                                }
                                break;
                            }
                            else if (z == 5)
                            {
                                z = 0;
                                
                                no();
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 19 + y * 1 <= 360)
                    {
                        if (w[x + y * 19 + y * 1] == 1)
                        {
                            z += 1;
                            if ((x + y * 19 + y * 1) % 19 == 0)
                            {
                                if (z == 5)
                                {
                                    z = 0;
                                    
                                    ok();
                                }
                                break;
                            }
                            else if (z == 5)
                            {
                                z = 0;
                                
                                ok();
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 19 + y * 1 <= 360)
                    {
                        if (w[x + y * 19 + y * 1] == 2)
                        {
                            z += 1;
                            if ((x + y * 19 + y * 1) % 19 == 0)
                            {
                                if (z == 5)
                                {
                                    z = 0;
                                    
                                    no();
                                }
                                break;
                            }
                            else if (z == 5)
                            {
                                z = 0;
                                
                                no();
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x + y * 19 - y * 1 <= 360)
                    {
                        if (w[x + y * 19 - y * 1] == 1)
                        {
                            z += 1;
                            if ((x + y * 19 - y * 1) % 19 == 0)
                            {
                                if (z == 5)
                                {
                                    z = 0;
                                    
                                    ok();
                                }
                                break;
                            }
                            else if (z == 5)
                            {
                                z = 0;
                                
                                ok();
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
                for (y = 0; y <= 5; y++)
                {
                    if (x < 284)
                    {
                        if (w[x + y * 19 - y * 1] == 2)
                        {
                            z += 1;
                            if ((x + y * 19 - y * 1) % 19 == 0)
                            {
                                if (z == 5)
                                {
                                    z = 0;
                                  
                                    no();
                                }
                                break;
                            }
                            else if (z == 5)
                            {
                                z = 0;
                                
                                no();
                            }
                        }
                        else
                        {
                            z = 0;
                            break;
                        }
                    }
                }
                z = 0;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("玩家退出\n游戏结束", "游戏结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
            if (1 == 1)
            {
                if (1 == 1)
                {
                    if (1 == 1)
                    {
                        if (1 == 1)
                        {
                            if (1 == 1)
                            {
                                if (1 == 1)
                                {
                                    if (1 == 1)
                                    {
                                        if (1 == 1)
                                        {
                                            if (1 == 1)
                                            {
                                                if (1 == 1)
                                                {
                                                    if (1 == 1)
                                                    {
                                                        if (1 == 1)
                                                        {
                                                            if (1 == 1)
                                                            {
                                                                if (1 == 1)
                                                                {
                                                                    if (1 == 1)
                                                                    {
                                                                        if (1 == 1)
                                                                        {
                                                                            if (1 == 1)
                                                                            {
                                                                                if (1 == 1)
                                                                                {
                                                                                    if (1 == 1)
                                                                                    {
                                                                                        if (1 == 1)
                                                                                        {
                                                                                            if (1 == 1)
                                                                                            {

                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("退出\n结束", "结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }       
    }
}